<?php

class auth {

    var $username;
    var $password;
    var $salt;

    public function __construct($sql_conn,$username,$password) {

        $this->sql=$sql_conn;

        $this->username = $username;
        $this->password = $password;
        $this->salt = "d83k6dj49";
        $this->salted_pass = $this->password.$this->salt;

    }

    public function check_user() {

        $query = "select username from users where username = '$this->username';";

        if ($this->sql->select($query)) {
            return true;
        } else {
            return false;
        }

    }

    public function create_user() {

        $query = "insert into users (username,password) values ('$this->username','$this->salted_pass');";
        $this->sql->write($query); 

    }

    public function login() {

        $query = "select * from users where username='$this->username' and password='$this->salted_pass'";

        if ($this->sql->select($query)) {

            $_SESSION['username'] = $this->username;

        } else {

            print "Login failed.<br />"; 
            return false;
        }

    }

}

?>
